package com.sgai.dcac;

import android.app.Application;
import android.util.Log;

import com.google.gson.GsonBuilder;
import com.sgai.dcac.utils.SharedPreferencesUtil;
import com.sgai.dcac.utils.UUIDUtil;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by tony on 2017/6/14.
 */

public class AppApplication extends Application {
    private static final String TAG = "AppApplication";
    private static AppApplication me;
    private Retrofit retrofit;
    @Override
    public void onCreate() {
        super.onCreate();
        me = this;
        Log.e(TAG,"AppApplication onCreate");
        //初始化数据
        if (SharedPreferencesUtil.isFirstExcute_1_0()) {
            SharedPreferencesUtil.setServerUrl("http://192.168.12.149:8088");
            SharedPreferencesUtil.setDeviceId(UUIDUtil.getMyUUID(me));
            SharedPreferencesUtil.setNoticeNumberHead("PH00");
            SharedPreferencesUtil.setNoticeNumber(30000000235l);
            SharedPreferencesUtil.setReceiptNumberHead("RN00");
            SharedPreferencesUtil.setReceiptNumber(50000000235l);
            SharedPreferencesUtil.setCacheKeepingTime(30);
            SharedPreferencesUtil.setIsFirstExcute_1_0(false);
        }

        //初始化网络请求
        retrofit = new Retrofit.Builder()
                .baseUrl("https://api.douban.com/v2/")
                .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().create()))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())//支持RxJava
                .build();
    }

    public static AppApplication getInstance () {
        return me;
    }

    public Retrofit getNormalRetrofit() {
        return retrofit;
    }
}
